/*
 * 注册协议展示页面
 * @Author: ljb
 * @Date: 2019-01-25 09:58:55
 * @Last Modified by: ljb
 * @Last Modified time: 2019-01-25 11:03:19
 */
<style lang="less" rel="stylesheet/less" type="text/less" scoped>
    @import '~src/assets/css/common.less';

    .v-agreement-views {
        padding: 120*@rem-per-px 20*@rem-per-px 20*@rem-per-px;
        .header{
            position: fixed;
            left: 0;
            top: 0;
			width: 100%;
			z-index: 999;
		}
    }
</style>
<template>
	<div
		class="v-agreement-views">
		<div class="header">
			<page-header
				:title="title"
				@back="backToHome"/>
		</div>
		<div
			class="agreement-container"
			v-html="register_agreement"/>
	</div>
</template>

<script>
import * as API_LIST from 'src/API_LIST';
import qs from 'qs';

import header from 'src/views/component/header';
import { appHandle } from 'src/views/mixins/appHandle';

export default {
	name: 'Agreement',
	components: {
		'page-header': header,
	},
	mixins: [appHandle],
	data() {
		return {
			title: this.$t('routers.agreement'),
			register_agreement: '',
		};
	},
	mounted() {
		this.fetchAgreement();
	},
	methods: {
		/**
         * 处理返回事件
         */
		backToHome() {
			this.handleApp('back');
		},
		/**
         * 获取注册协议
         */
		fetchAgreement() {
			const param = {
				language: this.$url.language || this.$url.lang,
			};

			const query_str = qs.stringify(param);

			return this.$http.get(`${API_LIST.APP_AGREEMENT}?${query_str}`)
				.then(({ data }) => {
					if (data.code !== 0) throw new Error(data.error);

					this.register_agreement = data.register_agreement;
				})
				.catch((err) => {
					const toast = this.$createToast({
						type: 'error',
						time: 2000,
						txt: err.message,
					});
					toast.show();
				});
		},
	},
};
</script>
